<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <script src="ezuikit.js"></script>
    <script src="jquery.min.js"></script>
    <script src="../js/common/tool.js"></script>
	<style>
		*{
			margin:0;
			padding:0;
			border-width:0;
			box-sizing: border-box;
			overflow:hidden;
		}
		#video-container{
			object-fit:fill;
		}
	</style>
</head>
<body style="margin: 0px;padding: 0px">
<div>
    <div id="video-container"></div>
  <!--  <div>
        <button onClick="play()">play</button>
        <button onClick="stop()">stop</button>
        <button onClick="getOSDTime()">getOSDTime</button>
        <button onClick="getOSDTime2()">getOSDTime2</button>
        <button onClick="capturePicture()">capturePicture</button>
        <button onClick="openSound()">openSound</button>
        <button onClick="closeSound()">closeSound</button>
        <button onClick="startSave()">startSave</button>
        <button onClick="stopSave()">stopSave</button>
        <button onClick="startTalk()">开始对讲</button>
        <button onClick="stopTalk()">结束对讲</button>
        <button onClick="fullScreen()">全屏</button>
    </div>-->
</div>
<script>
    var appKey;
    var appSecret;
    var deviceSerial;
    var checkCode;
    var iframeHeight;
    var playr;
	var videoMode = "standard";
    $(function(){


        appKey = $_GET.appKey;         //2ad643cdfbb8464fa5f295cce811edb1
        appSecret = $_GET.appSecret;     //4d55b1349d9224910eec0f0def338fdc
        deviceSerial = $_GET.deviceSerial;  //F37564104
        checkCode = $_GET.checkCode;     //JUIQIO
        iframeHeight = $_GET.iframeHeight; //
        iframeWidth = $_GET.iframeWidth; //
		videoMode = $_GET.videoMode;
		//console.log(videoMode);

        $.ajax({
            type: "POST",
            traditional: true,
            url:'https://open.ys7.com/api/lapp/token/get',
            data:{'appKey':appKey,'appSecret':appSecret},
            cache: false,
            async:false,
            beforeSend: function() {
                //请求前要处理的事情
            },
            success: function (data) {//
                accessToken =data.data.accessToken;

                 playr = new EZUIKit.EZUIKitPlayer({
                    id: 'video-container', // 视频容器ID
                    accessToken: accessToken,
                    //url: 'ezopen://open.ys7.com/F37564104/1.live',
                    url:'ezopen://'+checkCode+'@open.ys7.com/'+deviceSerial+'/1.live',
                    template:videoMode, // simple - 极简版;standard-标准版;security - 安防版(预览回放);voice-语音版; theme-可配置  主题；
                    autoplay: true,
                    audio: 0, // 是否默认开启声音 0 - 关闭 1 - 开启
                    plugin: ['talk'],                       // 加载插件，talk-对讲
                    handleSuccess: (data) = function(){console.log("播放成功回调",data)},
                    handleError: (data) => console.log("播放失败回调1",data),
                    handleTalkSuccess: () => console.log("对讲成功回调"),
                    handleTalkError: (data) = function(){console.log("对讲失败",data)},
                    decoderVersion: "v3.4",
                    width: iframeWidth,
                    height:iframeHeight,

                });


            },
            error: function (e) {
                alert("请求accessToken失败请联系管理员");
            }
        });


    });







    function fullScreen(){
        var playPromise = playr.fullScreen();
        playPromise.then((data)=>{
            console.log("promise 获取 数据",data)
        })
    }
    function play() {
        var playPromise = playr.play();
        playPromise.then((data)=>{
            console.log("promise 获取 数据",data)
        })
    }
    function stop() {
        var stopPromise = playr.stop();
        stopPromise.then((data)=>{
            console.log("promise 获取 数据",data)
        })
    }
    function getOSDTime() {
        var getOSDTimePromise = playr.getOSDTime();
        getOSDTimePromise.then((data)=>{
            console.log("promise 获取 数据",data)
        })
    }
    function getOSDTime2() {
        var getOSDTimePromise = playr2.getOSDTime();
        getOSDTimePromise.then((data)=>{
            console.log("promise 获取 数据",data)
        })
    }
    function capturePicture() {
        var capturePicturePromise = playr.capturePicture();
        capturePicturePromise.then((data)=>{
            console.log("promise 获取 数据",data)
        })
    }
    function openSound() {
        var openSoundPromise = playr.openSound();
        openSoundPromise.then((data)=>{
            console.log("promise 获取 数据",data)
        })
    }
    function closeSound() {
        var closeSoundPromise = playr.closeSound();
        closeSoundPromise.then((data)=>{
            console.log("promise 获取 数据",data)
        })
    }
    function startSave() {
        var startSavePromise = playr.startSave();
        startSavePromise.then((data)=>{
            console.log("promise 获取 数据",data)
        })
    }
    function stopSave() {
        var stopSavePromise = playr.stopSave();
        stopSavePromise.then((data)=>{
            console.log("promise 获取 数据",data)
        })
    }
	window.onbeforeunload=function(){
		playr.stop();
		console.log('视频关闭');
	}
</script>
</body>
</html>
